<template>
  <el-card>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="echart">
      <div id="main" style="width: 600px;height:400px;" ref="main"></div>
    </div>
  </el-card>
</template>

<script>
import { getReports } from "../../api/index";

export default {
  name: "hello",
  data() {
    return {
      options: {
        title: {
          text: "用户来源"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3"
            }
          }
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: "value"
          }
        ]
      },
      reportsData: ""
    };
  },
  methods: {
    /*  myEcharts() {
      // 基于准备好的dom，初始化echarts实例
      //   var myChart = this.$echarts.init(document.getElementById('main'));
      var myChart = this.$echarts.init(this.$refs.main);

      // 指定图表的配置项和数据

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(this.options);
    }, */

    async initGetReports() {
      let { data } = await getReports();
      console.log(data);
      //   this.reportsData = data;

      this.options = {
        ...this.options,
        ...data
      };

      var myChart = this.$echarts.init(this.$refs.main);
      myChart.setOption(this.options);
    }
  },
  async mounted() {
    await this.initGetReports();
    //  this.myEcharts();
  }
};
</script>

<style scoped lang="css">
#main {
  margin: 20px auto;
}

</style>
